<!DOCTYPE html>



  


<html class="theme-next gemini use-motion" lang="chinese">
<head><meta name="generator" content="Hexo 3.9.0">
  <meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
<meta name="theme-color" content="#222">



  
  
    
      
    
    
      
    
  <script src="//cdn.jsdelivr.net/npm/pace-js@1/pace.min.js"></script>
  <link href="//cdn.jsdelivr.net/npm/pace-js@1/themes/blue/pace-theme-minimal.min.css" rel="stylesheet">







<meta http-equiv="Cache-Control" content="no-transform">
<meta http-equiv="Cache-Control" content="no-siteapp">
















  
  
  <link href="/lib/fancybox/source/jquery.fancybox.css?v=2.1.5" rel="stylesheet" type="text/css">







<link href="/lib/font-awesome/css/font-awesome.min.css?v=4.6.2" rel="stylesheet" type="text/css">

<link href="/css/main.css?v=5.1.4" rel="stylesheet" type="text/css">


  <link rel="apple-touch-icon" sizes="180x180" href="/images/apple-touch-icon-next.png?v=5.1.4">


  <link rel="icon" type="image/png" sizes="32x32" href="/images/favicon-32x32-next.png?v=5.1.4">


  <link rel="icon" type="image/png" sizes="16x16" href="/images/favicon-16x16-next.png?v=5.1.4">


  <link rel="mask-icon" href="/images/logo.svg?v=5.1.4" color="#222">





  <meta name="keywords" content="Hexo, NexT">










<meta name="description" content="（引用 Spring Cloud 微服务实战） 一、基础知识1. 什么是微服务架构微服务是架构上的一种风格，服务之间通过HTTP的 RESTfu API 进行通信。 被拆分的小型服务都围绕着系统中的耦合高的业务进行构建。每个服务独立维护数据存储、业务、自动化测试以及独立部署。有了轻量级通讯协议，可以使用不同语言编写。 1.1 与单体应用的区别由于业务的扩展，单体应用变的臃肿。由于单体应用部署在一个">
<meta name="keywords" content="Java Php hexo Thinking in Java">
<meta property="og:type" content="article">
<meta property="og:title" content="Spring Cloud 简介 &amp; Spring Boot 快速理解使用">
<meta property="og:url" content="http://yoursite.com/2020/03/17/Spring-Cloud-简介-Spring-Boot-快速理解使用/index.html">
<meta property="og:site_name" content="坚持就是胜利">
<meta property="og:description" content="（引用 Spring Cloud 微服务实战） 一、基础知识1. 什么是微服务架构微服务是架构上的一种风格，服务之间通过HTTP的 RESTfu API 进行通信。 被拆分的小型服务都围绕着系统中的耦合高的业务进行构建。每个服务独立维护数据存储、业务、自动化测试以及独立部署。有了轻量级通讯协议，可以使用不同语言编写。 1.1 与单体应用的区别由于业务的扩展，单体应用变的臃肿。由于单体应用部署在一个">
<meta property="og:locale" content="chinese">
<meta property="og:updated_time" content="2020-03-17T09:13:38.924Z">
<meta name="twitter:card" content="summary">
<meta name="twitter:title" content="Spring Cloud 简介 &amp; Spring Boot 快速理解使用">
<meta name="twitter:description" content="（引用 Spring Cloud 微服务实战） 一、基础知识1. 什么是微服务架构微服务是架构上的一种风格，服务之间通过HTTP的 RESTfu API 进行通信。 被拆分的小型服务都围绕着系统中的耦合高的业务进行构建。每个服务独立维护数据存储、业务、自动化测试以及独立部署。有了轻量级通讯协议，可以使用不同语言编写。 1.1 与单体应用的区别由于业务的扩展，单体应用变的臃肿。由于单体应用部署在一个">



<script type="text/javascript" id="hexo.configurations">
  var NexT = window.NexT || {};
  var CONFIG = {
    root: '/',
    scheme: 'Gemini',
    version: '5.1.4',
    sidebar: {"position":"left","display":"post","offset":14,"b2t":false,"scrollpercent":false,"onmobile":false},
    fancybox: true,
    tabs: true,
    motion: {"enable":true,"async":false,"transition":{"post_block":"fadeIn","post_header":"slideDownIn","post_body":"slideDownIn","coll_header":"slideLeftIn","sidebar":"slideUpIn"}},
    duoshuo: {
      userId: '0',
      author: '190coder'
    },
    algolia: {
      applicationID: '',
      apiKey: '',
      indexName: '',
      hits: {"per_page":10},
      labels: {"input_placeholder":"Search for Posts","hits_empty":"We didn't find any results for the search: ${query}","hits_stats":"${hits} results found in ${time} ms"}
    }
  };
</script>



  <link rel="canonical" href="http://yoursite.com/2020/03/17/Spring-Cloud-简介-Spring-Boot-快速理解使用/">





  <title>Spring Cloud 简介 & Spring Boot 快速理解使用 | 坚持就是胜利</title>
  








</head>

<body itemscope itemtype="http://schema.org/WebPage" lang="chinese">

  
  
    
  

  <div class="container sidebar-position-left page-post-detail">
    <div class="headband"></div>

    <header id="header" class="header" itemscope itemtype="http://schema.org/WPHeader">
      <div class="header-inner"><div class="site-brand-wrapper">
  <div class="site-meta ">
    

    <div class="custom-logo-site-title">
      <a href="/" class="brand" rel="start">
        <span class="logo-line-before"><i></i></span>
        <span class="site-title">坚持就是胜利</span>
        <span class="logo-line-after"><i></i></span>
      </a>
    </div>
      
        <p class="site-subtitle"></p>
      
  </div>

  <div class="site-nav-toggle">
    <button>
      <span class="btn-bar"></span>
      <span class="btn-bar"></span>
      <span class="btn-bar"></span>
    </button>
  </div>
</div>

<nav class="site-nav">
  

  
    <ul id="menu" class="menu">
      
        
        <li class="menu-item menu-item-home">
          <a href="/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-home"></i> <br>
            
            Home
          </a>
        </li>
      
        
        <li class="menu-item menu-item-categories">
          <a href="/categories/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-th"></i> <br>
            
            Categories
          </a>
        </li>
      
        
        <li class="menu-item menu-item-archives">
          <a href="/archives/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-archive"></i> <br>
            
            Archives
          </a>
        </li>
      

      
    </ul>
  

  
</nav>



 </div>
    </header>

    <main id="main" class="main">
      <div class="main-inner">
        <div class="content-wrap">
          <div id="content" class="content">
            

  <div id="posts" class="posts-expand">
    

  

  
  
  

  <article class="post post-type-normal" itemscope itemtype="http://schema.org/Article">
  
  
  
  <div class="post-block">
    <link itemprop="mainEntityOfPage" href="http://yoursite.com/2020/03/17/Spring-Cloud-简介-Spring-Boot-快速理解使用/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="name" content="190coder">
      <meta itemprop="description" content>
      <meta itemprop="image" content="/images/avatar.jpg">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="坚持就是胜利">
    </span>

    
      <header class="post-header">

        
        
          <h1 class="post-title" itemprop="name headline">Spring Cloud 简介 & Spring Boot 快速理解使用</h1>
        

        <div class="post-meta">
          <span class="post-time">
            
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              
                <span class="post-meta-item-text">Posted on</span>
              
              <time title="Post created" itemprop="dateCreated datePublished" datetime="2020-03-17T09:52:59+08:00">
                2020-03-17
              </time>
            

            

            
          </span>

          
            <span class="post-category">
            
              <span class="post-meta-divider">|</span>
            
              <span class="post-meta-item-icon">
                <i class="fa fa-folder-o"></i>
              </span>
              
                <span class="post-meta-item-text">In</span>
              
              
                <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
                  <a href="/categories/Spring/" itemprop="url" rel="index">
                    <span itemprop="name">Spring</span>
                  </a>
                </span>

                
                
              
            </span>
          

          
            
          

          
          

          

          

          

        </div>
      </header>
    

    
    
    
    <div class="post-body" itemprop="articleBody">

      
      

      
        <p>（引用 Spring Cloud 微服务实战）</p>
<h1 id="一、基础知识"><a href="#一、基础知识" class="headerlink" title="一、基础知识"></a>一、基础知识</h1><h2 id="1-什么是微服务架构"><a href="#1-什么是微服务架构" class="headerlink" title="1. 什么是微服务架构"></a>1. 什么是微服务架构</h2><p>微服务是架构上的一种风格，服务之间通过HTTP的 RESTfu API 进行通信。 被拆分的小型服务都围绕着系统中的耦合高的业务进行构建。每个服务独立维护数据存储、业务、自动化测试以及独立部署。有了轻量级通讯协议，可以使用不同语言编写。</p>
<h4 id="1-1-与单体应用的区别"><a href="#1-1-与单体应用的区别" class="headerlink" title="1.1 与单体应用的区别"></a>1.1 与单体应用的区别</h4><p>由于业务的扩展，单体应用变的臃肿。由于单体应用部署在一个进程，修改一处，牵扯所有应用。由此微服务诞生了。</p>
<h4 id="1-2-实施微服务"><a href="#1-2-实施微服务" class="headerlink" title="1.2 实施微服务"></a>1.2 实施微服务</h4><ol>
<li>微服务带来的问题</li>
</ol>
<ul>
<li>运维需要更多自动化</li>
<li>接口需要一致性</li>
<li>分布式更加复杂 如：网络延迟、分布式事务、异步消息等。</li>
</ul>
<ol start="2">
<li><p>服务组件化，由于服务拆分，只需更换服务地址就能升级PC计算能力。</p>
</li>
<li><p>按业务拆分团队，团队边界变的更加清晰。</p>
</li>
<li><p>以做产品的态度去对待业务，而不是项目</p>
</li>
</ol>
<h5 id="智能端点与哑管道"><a href="#智能端点与哑管道" class="headerlink" title="智能端点与哑管道"></a>智能端点与哑管道</h5><p>单体应用直接通过函数调用交互协作，微服务使用RPC调用，导致微服务之间产生繁琐的通信，使得系统表现更糟糕，所以我们要更粗粒度的通信协议。通常以2种服务讨论方式：</p>
<ul>
<li>HTTP 的RESTful API 或轻量级的消息发送协议。</li>
<li>通过在在轻量的消息总线上传递消息，如 RabbitMQ 等一些提供可靠异步交换中间件。</li>
</ul>
<h5 id="去中心化治理"><a href="#去中心化治理" class="headerlink" title="去中心化治理"></a>去中心化治理</h5><p>每一个技术平台都有短板，针对不用的业务选择不同的技术平台，不要杀鸡用牛刀。<strong>不是每个问题都是钉子，不是每个解决方案都是锤子</strong></p>
<h5 id="去中心化管理数据"><a href="#去中心化管理数据" class="headerlink" title="去中心化管理数据"></a>去中心化管理数据</h5><p>强调 “无事务”调用，分布式事务本身难度就非常大，若过程出现错误，通过补偿机制来进行处理，使得错误数据来达到最终一致性。</p>
<h5 id="基础设施自动化"><a href="#基础设施自动化" class="headerlink" title="基础设施自动化"></a>基础设施自动化</h5><p>自动化部署，自动化测试。要不然多个容器配置 发布上线，会是噩梦。</p>
<h5 id="容错设计"><a href="#容错设计" class="headerlink" title="容错设计"></a>容错设计</h5><p>A 调用 B ，B 调用 C，有一个故障，就会故障蔓延。 要快速通过每个容器的事实监控和日志去找到问题所在。如：服务状态、吞吐量、网络延迟等</p>
<h5 id="演进式设计"><a href="#演进式设计" class="headerlink" title="演进式设计"></a>演进式设计</h5><p>设计微服务，成本很大，初期经验不足可以先讲单体应用经常变动或者时间效应高的拆分微服务处理。将稳定不变的东西去形成一个核心的服务存储与整个架构之中。</p>
<h2 id="2-为什选择Spring-Cloud"><a href="#2-为什选择Spring-Cloud" class="headerlink" title="2 为什选择Spring Cloud"></a>2 为什选择Spring Cloud</h2><p>业内贡献出的微服务解决方案为了弥补各自公司拆分后的问题而诞生的。而使用Spring Cloud 是一个整合，综合性解决框架。况且有Spring 强大背景，和社区活跃度，是一个标准解决方案。</p>
<h4 id="2-1-Spring-Cloud-简介"><a href="#2-1-Spring-Cloud-简介" class="headerlink" title="2.1 Spring Cloud 简介"></a>2.1 Spring Cloud 简介</h4><p>它涉及 配置管理、服务治理、断路器、智能路由、微代理、控制总线、全局锁、决策竞选、分布式会话和集群状态管理等操作提供了一种简单的开发方式。</p>
<p>包含如下子项目：</p>
<ul>
<li><p>Spring Cloud Config： 配置管理工具 ，支持使用Git 存储配置内容。</p>
</li>
<li><p>Spring Cloud Netflix： 核心组件</p>
<ul>
<li>Eureka ：服务治理组件，包含服务注册中心、服务注册与服务发现机制的实现。</li>
<li>Hystrix ：容错管理组件，实现断路器模式，帮助服务依赖出现的延迟和为故障提供的强大容错能力。</li>
<li>Ribbon ：负载均衡的服务调用组件。</li>
</ul>
</li>
</ul>
<p>剩下还有很多组件，上网查阅。</p>
<h4 id="2-2-Spring-Cloud-版本-问题"><a href="#2-2-Spring-Cloud-版本-问题" class="headerlink" title="2.2 Spring Cloud 版本 问题"></a>2.2 Spring Cloud 版本 问题</h4><p>防止混淆，版本通过命名方式，例如 Brixtion.SR5 就是 Brixtion的第5个Release 版本。</p>
<p><strong>由于Cloud 更新较快，故查阅资料要尽量查阅最新，以免出坑。</strong></p>
<h1 id="二、微服务构建-Sping-Boot"><a href="#二、微服务构建-Sping-Boot" class="headerlink" title="二、微服务构建 Sping Boot"></a>二、微服务构建 Sping Boot</h1><p>Sping Boot 是 Cloud 构建的基础框架，并且还有自动化配置、快速开发、轻松部署等优势。非常适合做微服务开发框架。</p>
<h2 id="1-Spring-Boot-简介"><a href="#1-Spring-Boot-简介" class="headerlink" title="1. Spring Boot 简介"></a>1. Spring Boot 简介</h2><p>Spring 框架繁琐，每次新构建都需要复制粘贴差不多的配置文件这种枯燥无谓的事。Spirng Boot 的出现就可以有效改善这类问题， Spring Boot 的宗旨并非重写Spring 或代替Spring 而是希望通过涉及大量自动化配置来简化Spring 原有的样板化配置，使得开发着快速构建项目。</p>
<p>除此之外，Spring Boot 还通过一系列Starter POMs 定义，简化pom.xml 维护错综复杂的依赖关系，使得依赖更加简单。</p>
<p>如今容器化大行其道，Spring Boot 除了融入Docker，自身支持其嵌入 Tomcat、Jetty 等容器。运行直接java -jar 运行启用标准Web应用。</p>
<h2 id="2-快速入门"><a href="#2-快速入门" class="headerlink" title="2. 快速入门"></a>2. 快速入门</h2><p>在项目依赖配置中，包含2项：</p>
<ul>
<li>spring-boot-starter-web ： 全栈Web 开发模块，包含嵌入式Tomcat、SpringMVC。</li>
<li>spring-boot-starter-test ：包含 JUnit、Hancrest、Mockito。</li>
</ul>
<p>需要访问数据库 加上 spring-boot-starter-jdbc 或者 更好用的spring-boot-starter-jpa ，这样通过Starter POMs 定义的依赖包，使得功能模块变的非常轻巧，易于理解使用。</p>
<p>构建build 引入了 Spring Boot 的 Maven插件， 通过 mvn spring-boot:run 命令快速启动。</p>
<h4 id="2-1-实现RESTful-API"><a href="#2-1-实现RESTful-API" class="headerlink" title="2.1 实现RESTful API"></a>2.1 实现RESTful API</h4><p>增加@RestController 注解可以将类设置为Controller 并返回RESTful 规范的json。</p>
<h4 id="2-2-单元测试"><a href="#2-2-单元测试" class="headerlink" title="2.2 单元测试"></a>2.2 单元测试</h4><p>直接上代码，注解 描述请看注释</p>
<p><strong>注意 @Test @Before 都需要统一包前缀，否则 before 失效</strong></p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br></pre></td><td class="code"><pre><span class="line">package com.zjn.cloud.eurekaclient;</span><br><span class="line"></span><br><span class="line">import org.junit.Before;</span><br><span class="line">import org.junit.Test;</span><br><span class="line">import org.junit.runner.RunWith;</span><br><span class="line">import org.springframework.boot.test.context.SpringBootTest;</span><br><span class="line">import org.springframework.http.MediaType;</span><br><span class="line">import org.springframework.test.context.junit4.SpringRunner;</span><br><span class="line">import org.springframework.test.context.web.WebAppConfiguration;</span><br><span class="line">import org.springframework.test.web.servlet.MockMvc;</span><br><span class="line">import org.springframework.test.web.servlet.request.MockMvcRequestBuilders;</span><br><span class="line">import org.springframework.test.web.servlet.setup.MockMvcBuilders;</span><br><span class="line">import static org.hamcrest.Matchers.equalTo;</span><br><span class="line">import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content;</span><br><span class="line">import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;</span><br><span class="line"></span><br><span class="line">@RunWith(SpringRunner.class) // 引入 spring 对 JUnit4 的支持</span><br><span class="line">@WebAppConfiguration // 开启Web应用配置，用于模拟ServletContext</span><br><span class="line">@SpringBootTest //模拟Spring Boot 启动类</span><br><span class="line">public class EurekaClientApplicationTests &#123;</span><br><span class="line"></span><br><span class="line">    private MockMvc mvc; // 模拟对Controller 发起请求，perform 执行请求 accept接收数据类型 andExpect 判断接口返回期望值</span><br><span class="line"></span><br><span class="line">    @Before</span><br><span class="line">    public void  setup()&#123;</span><br><span class="line">        mvc = MockMvcBuilders.standaloneSetup(new HelloController()).build();</span><br><span class="line">    &#125;</span><br><span class="line">    @Test</span><br><span class="line">    public void testHello() throws Exception&#123;</span><br><span class="line"></span><br><span class="line">        mvc.perform(MockMvcRequestBuilders.get(&quot;/hello&quot;).accept(MediaType.APPLICATION_JSON))</span><br><span class="line">                .andExpect(status().isOk())</span><br><span class="line">                .andExpect(content().string(equalTo(&quot;hello&quot;)));</span><br><span class="line">    &#125;</span><br><span class="line"> </span><br><span class="line"></span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<h2 id="3-配置详解"><a href="#3-配置详解" class="headerlink" title="3 配置详解"></a>3 配置详解</h2><h4 id="3-1-配置文件"><a href="#3-1-配置文件" class="headerlink" title="3.1 配置文件"></a>3.1 配置文件</h4><p>yml</p>
<h4 id="3-2-自定义参数"><a href="#3-2-自定义参数" class="headerlink" title="3.2 自定义参数"></a>3.2 自定义参数</h4><p>在 yml 中设置 @value 注解 取出</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">@Value(&quot;$&#123;book.name&#125;&quot;)</span><br></pre></td></tr></table></figure>

<h4 id="3-3-参数引用"><a href="#3-3-参数引用" class="headerlink" title="3.3 参数引用"></a>3.3 参数引用</h4><p>配置文件中 使用 <figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">#### 3.4 使用随机数</span><br><span class="line"></span><br><span class="line">```$&#123;random.value&#125;</span><br></pre></td></tr></table></figure></p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line">#### 3.5 命令行参数</span><br><span class="line"></span><br><span class="line">java -jar xxx.jar --server.port=8000</span><br><span class="line"></span><br><span class="line">#### 3.6多环境配置</span><br></pre></td></tr></table></figure>

<p>application-dev.yml<br>application-test.yml<br>application-prod.yml</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br></pre></td><td class="code"><pre><span class="line">通过 ```java -jar xxx.jar --server.port=8000 --spring.profiles.active=dev``` 选择开发环境</span><br><span class="line"></span><br><span class="line">#### 3.7 加载顺序</span><br><span class="line">Spring Boot 数据文件加载顺序 （不熟悉会造成安全隐患）</span><br><span class="line">1. 命令行参数</span><br><span class="line">2. SPRING_APPLICATION_JSON 中的属性。 它是以Json 格式配置在系统环境变量中设置的内容</span><br><span class="line">3. Java:comp/env 重的JNDI属性</span><br><span class="line">4. Java 系统属性 ```System.getProperties()``` 获得</span><br><span class="line">5. 操作系统环境变量</span><br><span class="line">6. 通过random.* 配置的随机属性</span><br><span class="line">7. 当前应用jar包外配置内容 例如 application-prod.yml 配置文件</span><br><span class="line">8. 当前应用jar包内的配置文件  application-prod.yml</span><br><span class="line">9. 当前应用jar包外配置内容 例如 application.yml 配置文件</span><br><span class="line">10. 当前应用jar包内的配置文件  application.yml</span><br><span class="line">11. @Configuration 注解修改的类中，通过@PropertySource 注解定义的属性</span><br><span class="line">12. 应用默认属性，使用SpringApplication.setDefaultProperties 定义的内容。</span><br><span class="line">优先级由低到高</span><br><span class="line"></span><br><span class="line">常用 第7 和 第9 项，这样 工程在配置变的非常干净，只需在本地放置开发的配置即可。</span><br><span class="line"></span><br><span class="line">## 4. 监控与管理</span><br><span class="line"></span><br><span class="line">spring-boot-starter-actuatorboot-starter-actuator提供一系列 用于监控的端点。 同时，Spring Cloud 在实现各个微服务组件的时候，进一步做了不少扩展。如 整合 Eureka 会为 /health 端点增加相关的信息 ，为API 网关提供了/routes 端点开返回路由信息。</span><br><span class="line"></span><br><span class="line">#### 4.1 初识 actuator</span><br></pre></td></tr></table></figure>

 <dependency>
            <groupid>org.springframework.boot</groupid>
            <artifactid>spring-boot-starter-actuator</artifactid>
</dependency>
```
actuator 相关监控端口很多，不举例了，可上网查阅。

<h2 id="5-小结"><a href="#5-小结" class="headerlink" title="5. 小结"></a>5. 小结</h2><p>主要写了Spring Boot 的配置原理以及监控管理做了一些介绍。</p>

      
    </div>
    
    
    

    

    

    

    <footer class="post-footer">
      

      
      
      

      
        <div class="post-nav">
          <div class="post-nav-next post-nav-item">
            
              <a href="/2020/03/03/Thinking-in-Java-第二十一章/" rel="next" title="Thinking in Java 第二十一章">
                <i class="fa fa-chevron-left"></i> Thinking in Java 第二十一章
              </a>
            
          </div>

          <span class="post-nav-divider"></span>

          <div class="post-nav-prev post-nav-item">
            
              <a href="/2020/03/17/Spring-Cloud-Ribbon/" rel="prev" title="Spring Cloud Ribbon">
                Spring Cloud Ribbon <i class="fa fa-chevron-right"></i>
              </a>
            
          </div>
        </div>
      

      
      
    </footer>
  </div>
  
  
  
  </article>



    <div class="post-spread">
      
    </div>
  </div>


          </div>
          


          

  



        </div>
        
          
  
  <div class="sidebar-toggle">
    <div class="sidebar-toggle-line-wrap">
      <span class="sidebar-toggle-line sidebar-toggle-line-first"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-middle"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-last"></span>
    </div>
  </div>

  <aside id="sidebar" class="sidebar">
    
    <div class="sidebar-inner">

      

      
        <ul class="sidebar-nav motion-element">
          <li class="sidebar-nav-toc sidebar-nav-active" data-target="post-toc-wrap">
            Table of Contents
          </li>
          <li class="sidebar-nav-overview" data-target="site-overview-wrap">
            Overview
          </li>
        </ul>
      

      <section class="site-overview-wrap sidebar-panel">
        <div class="site-overview">
          <div class="site-author motion-element" itemprop="author" itemscope itemtype="http://schema.org/Person">
            
              <img class="site-author-image" itemprop="image" src="/images/avatar.jpg" alt="190coder">
            
              <p class="site-author-name" itemprop="name">190coder</p>
              <p class="site-description motion-element" itemprop="description">坚信持续学习就一定能超过大多数人</p>
          </div>

          <nav class="site-state motion-element">

            
              <div class="site-state-item site-state-posts">
              
                <a href="/archives/">
              
                  <span class="site-state-item-count">53</span>
                  <span class="site-state-item-name">posts</span>
                </a>
              </div>
            

            
              
              
              <div class="site-state-item site-state-categories">
                <a href="/categories/index.html">
                  <span class="site-state-item-count">13</span>
                  <span class="site-state-item-name">categories</span>
                </a>
              </div>
            

            

          </nav>

          

          

          
          

          
          

          <div style>
  <canvas id="canvas" style="width:60%;">当前浏览器不支持canvas，请更换浏览器后再试</canvas>
</div>
<script>
(function(){

   var digit=
    [
        [
            [0,0,1,1,1,0,0],
            [0,1,1,0,1,1,0],
            [1,1,0,0,0,1,1],
            [1,1,0,0,0,1,1],
            [1,1,0,0,0,1,1],
            [1,1,0,0,0,1,1],
            [1,1,0,0,0,1,1],
            [1,1,0,0,0,1,1],
            [0,1,1,0,1,1,0],
            [0,0,1,1,1,0,0]
        ],//0
        [
            [0,0,0,1,1,0,0],
            [0,1,1,1,1,0,0],
            [0,0,0,1,1,0,0],
            [0,0,0,1,1,0,0],
            [0,0,0,1,1,0,0],
            [0,0,0,1,1,0,0],
            [0,0,0,1,1,0,0],
            [0,0,0,1,1,0,0],
            [0,0,0,1,1,0,0],
            [1,1,1,1,1,1,1]
        ],//1
        [
            [0,1,1,1,1,1,0],
            [1,1,0,0,0,1,1],
            [0,0,0,0,0,1,1],
            [0,0,0,0,1,1,0],
            [0,0,0,1,1,0,0],
            [0,0,1,1,0,0,0],
            [0,1,1,0,0,0,0],
            [1,1,0,0,0,0,0],
            [1,1,0,0,0,1,1],
            [1,1,1,1,1,1,1]
        ],//2
        [
            [1,1,1,1,1,1,1],
            [0,0,0,0,0,1,1],
            [0,0,0,0,1,1,0],
            [0,0,0,1,1,0,0],
            [0,0,1,1,1,0,0],
            [0,0,0,0,1,1,0],
            [0,0,0,0,0,1,1],
            [0,0,0,0,0,1,1],
            [1,1,0,0,0,1,1],
            [0,1,1,1,1,1,0]
        ],//3
        [
            [0,0,0,0,1,1,0],
            [0,0,0,1,1,1,0],
            [0,0,1,1,1,1,0],
            [0,1,1,0,1,1,0],
            [1,1,0,0,1,1,0],
            [1,1,1,1,1,1,1],
            [0,0,0,0,1,1,0],
            [0,0,0,0,1,1,0],
            [0,0,0,0,1,1,0],
            [0,0,0,1,1,1,1]
        ],//4
        [
            [1,1,1,1,1,1,1],
            [1,1,0,0,0,0,0],
            [1,1,0,0,0,0,0],
            [1,1,1,1,1,1,0],
            [0,0,0,0,0,1,1],
            [0,0,0,0,0,1,1],
            [0,0,0,0,0,1,1],
            [0,0,0,0,0,1,1],
            [1,1,0,0,0,1,1],
            [0,1,1,1,1,1,0]
        ],//5
        [
            [0,0,0,0,1,1,0],
            [0,0,1,1,0,0,0],
            [0,1,1,0,0,0,0],
            [1,1,0,0,0,0,0],
            [1,1,0,1,1,1,0],
            [1,1,0,0,0,1,1],
            [1,1,0,0,0,1,1],
            [1,1,0,0,0,1,1],
            [1,1,0,0,0,1,1],
            [0,1,1,1,1,1,0]
        ],//6
        [
            [1,1,1,1,1,1,1],
            [1,1,0,0,0,1,1],
            [0,0,0,0,1,1,0],
            [0,0,0,0,1,1,0],
            [0,0,0,1,1,0,0],
            [0,0,0,1,1,0,0],
            [0,0,1,1,0,0,0],
            [0,0,1,1,0,0,0],
            [0,0,1,1,0,0,0],
            [0,0,1,1,0,0,0]
        ],//7
        [
            [0,1,1,1,1,1,0],
            [1,1,0,0,0,1,1],
            [1,1,0,0,0,1,1],
            [1,1,0,0,0,1,1],
            [0,1,1,1,1,1,0],
            [1,1,0,0,0,1,1],
            [1,1,0,0,0,1,1],
            [1,1,0,0,0,1,1],
            [1,1,0,0,0,1,1],
            [0,1,1,1,1,1,0]
        ],//8
        [
            [0,1,1,1,1,1,0],
            [1,1,0,0,0,1,1],
            [1,1,0,0,0,1,1],
            [1,1,0,0,0,1,1],
            [0,1,1,1,0,1,1],
            [0,0,0,0,0,1,1],
            [0,0,0,0,0,1,1],
            [0,0,0,0,1,1,0],
            [0,0,0,1,1,0,0],
            [0,1,1,0,0,0,0]
        ],//9
        [
            [0,0,0,0,0,0,0],
            [0,0,1,1,1,0,0],
            [0,0,1,1,1,0,0],
            [0,0,1,1,1,0,0],
            [0,0,0,0,0,0,0],
            [0,0,0,0,0,0,0],
            [0,0,1,1,1,0,0],
            [0,0,1,1,1,0,0],
            [0,0,1,1,1,0,0],
            [0,0,0,0,0,0,0]
        ]//:
    ];

var canvas = document.getElementById('canvas');

if(canvas.getContext){
    var cxt = canvas.getContext('2d');
    //声明canvas的宽高
    var H = 100,W = 700;
    canvas.height = H;
    canvas.width = W;
    cxt.fillStyle = '#f00';
    cxt.fillRect(10,10,50,50);

    //存储时间数据
    var data = [];
    //存储运动的小球
    var balls = [];
    //设置粒子半径
    var R = canvas.height/20-1;
    (function(){
        var temp = /(\d)(\d):(\d)(\d):(\d)(\d)/.exec(new Date());
        //存储时间数字，由十位小时、个位小时、冒号、十位分钟、个位分钟、冒号、十位秒钟、个位秒钟这7个数字组成
        data.push(temp[1],temp[2],10,temp[3],temp[4],10,temp[5],temp[6]);
    })();

    /*生成点阵数字*/
    function renderDigit(index,num){
        for(var i = 0; i < digit[num].length; i++){
            for(var j = 0; j < digit[num][i].length; j++){
                if(digit[num][i][j] == 1){
                    cxt.beginPath();
                    cxt.arc(14*(R+2)*index + j*2*(R+1)+(R+1),i*2*(R+1)+(R+1),R,0,2*Math.PI);
                    cxt.closePath();
                    cxt.fill();
                }
            }
        }
    }

    /*更新时钟*/
    function updateDigitTime(){
        var changeNumArray = [];
        var temp = /(\d)(\d):(\d)(\d):(\d)(\d)/.exec(new Date());
        var NewData = [];
        NewData.push(temp[1],temp[2],10,temp[3],temp[4],10,temp[5],temp[6]);
        for(var i = data.length-1; i >=0 ; i--){
            //时间发生变化
            if(NewData[i] !== data[i]){
                //将变化的数字值和在data数组中的索引存储在changeNumArray数组中
                changeNumArray.push(i+'_'+(Number(data[i])+1)%10);
            }
        }
        //增加小球
        for(var i = 0; i< changeNumArray.length; i++){
            addBalls.apply(this,changeNumArray[i].split('_'));
        }
        data = NewData.concat();
    }

    /*更新小球状态*/
    function updateBalls(){
        for(var i = 0; i < balls.length; i++){
            balls[i].stepY += balls[i].disY;
            balls[i].x += balls[i].stepX;
            balls[i].y += balls[i].stepY;
            if(balls[i].x > W + R || balls[i].y > H + R){
                balls.splice(i,1);
                i--;
            }
        }
    }

    /*增加要运动的小球*/
    function addBalls(index,num){
        var numArray = [1,2,3];
        var colorArray =  ["#3BE","#09C","#A6C","#93C","#9C0","#690","#FB3","#F80","#F44","#C00"];
        for(var i = 0; i < digit[num].length; i++){
            for(var j = 0; j < digit[num][i].length; j++){
                if(digit[num][i][j] == 1){
                    var ball = {
                        x:14*(R+2)*index + j*2*(R+1)+(R+1),
                        y:i*2*(R+1)+(R+1),
                        stepX:Math.floor(Math.random() * 4 -2),
                        stepY:-2*numArray[Math.floor(Math.random()*numArray.length)],
                        color:colorArray[Math.floor(Math.random()*colorArray.length)],
                        disY:1
                    };
                    balls.push(ball);
                }
            }
        }
    }

    /*渲染*/
    function render(){
        //重置画布宽度，达到清空画布的效果
        canvas.height = 100;
        //渲染时钟
        for(var i = 0; i < data.length; i++){
            renderDigit(i,data[i]);
        }
        //渲染小球
        for(var i = 0; i < balls.length; i++){
            cxt.beginPath();
            cxt.arc(balls[i].x,balls[i].y,R,0,2*Math.PI);
            cxt.fillStyle = balls[i].color;
            cxt.closePath();
            cxt.fill();
        }
    }

    clearInterval(oTimer);
    var oTimer = setInterval(function(){
        //更新时钟
        updateDigitTime();
        //更新小球状态
        updateBalls();
        //渲染
        render();
    },50);
}

})();
</script>



        </div>
      </section>

      
      <!--noindex-->
        <section class="post-toc-wrap motion-element sidebar-panel sidebar-panel-active">
          <div class="post-toc">

            
              
            

            
              <div class="post-toc-content"><ol class="nav"><li class="nav-item nav-level-1"><a class="nav-link" href="#一、基础知识"><span class="nav-number">1.</span> <span class="nav-text">一、基础知识</span></a><ol class="nav-child"><li class="nav-item nav-level-2"><a class="nav-link" href="#1-什么是微服务架构"><span class="nav-number">1.1.</span> <span class="nav-text">1. 什么是微服务架构</span></a><ol class="nav-child"><li class="nav-item nav-level-4"><a class="nav-link" href="#1-1-与单体应用的区别"><span class="nav-number">1.1.0.1.</span> <span class="nav-text">1.1 与单体应用的区别</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#1-2-实施微服务"><span class="nav-number">1.1.0.2.</span> <span class="nav-text">1.2 实施微服务</span></a><ol class="nav-child"><li class="nav-item nav-level-5"><a class="nav-link" href="#智能端点与哑管道"><span class="nav-number">1.1.0.2.1.</span> <span class="nav-text">智能端点与哑管道</span></a></li><li class="nav-item nav-level-5"><a class="nav-link" href="#去中心化治理"><span class="nav-number">1.1.0.2.2.</span> <span class="nav-text">去中心化治理</span></a></li><li class="nav-item nav-level-5"><a class="nav-link" href="#去中心化管理数据"><span class="nav-number">1.1.0.2.3.</span> <span class="nav-text">去中心化管理数据</span></a></li><li class="nav-item nav-level-5"><a class="nav-link" href="#基础设施自动化"><span class="nav-number">1.1.0.2.4.</span> <span class="nav-text">基础设施自动化</span></a></li><li class="nav-item nav-level-5"><a class="nav-link" href="#容错设计"><span class="nav-number">1.1.0.2.5.</span> <span class="nav-text">容错设计</span></a></li><li class="nav-item nav-level-5"><a class="nav-link" href="#演进式设计"><span class="nav-number">1.1.0.2.6.</span> <span class="nav-text">演进式设计</span></a></li></ol></li></ol></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#2-为什选择Spring-Cloud"><span class="nav-number">1.2.</span> <span class="nav-text">2 为什选择Spring Cloud</span></a><ol class="nav-child"><li class="nav-item nav-level-4"><a class="nav-link" href="#2-1-Spring-Cloud-简介"><span class="nav-number">1.2.0.1.</span> <span class="nav-text">2.1 Spring Cloud 简介</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#2-2-Spring-Cloud-版本-问题"><span class="nav-number">1.2.0.2.</span> <span class="nav-text">2.2 Spring Cloud 版本 问题</span></a></li></ol></li></ol><li class="nav-item nav-level-1"><a class="nav-link" href="#二、微服务构建-Sping-Boot"><span class="nav-number">2.</span> <span class="nav-text">二、微服务构建 Sping Boot</span></a><ol class="nav-child"><li class="nav-item nav-level-2"><a class="nav-link" href="#1-Spring-Boot-简介"><span class="nav-number">2.1.</span> <span class="nav-text">1. Spring Boot 简介</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#2-快速入门"><span class="nav-number">2.2.</span> <span class="nav-text">2. 快速入门</span></a><ol class="nav-child"><li class="nav-item nav-level-4"><a class="nav-link" href="#2-1-实现RESTful-API"><span class="nav-number">2.2.0.1.</span> <span class="nav-text">2.1 实现RESTful API</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#2-2-单元测试"><span class="nav-number">2.2.0.2.</span> <span class="nav-text">2.2 单元测试</span></a></li></ol></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#3-配置详解"><span class="nav-number">2.3.</span> <span class="nav-text">3 配置详解</span></a><ol class="nav-child"><li class="nav-item nav-level-4"><a class="nav-link" href="#3-1-配置文件"><span class="nav-number">2.3.0.1.</span> <span class="nav-text">3.1 配置文件</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#3-2-自定义参数"><span class="nav-number">2.3.0.2.</span> <span class="nav-text">3.2 自定义参数</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#3-3-参数引用"><span class="nav-number">2.3.0.3.</span> <span class="nav-text">3.3 参数引用</span></a></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#5-小结"><span class="nav-number">2.4.</span> <span class="nav-text">5. 小结</span></a></li></div>
            

          </div>
        </section>
      <!--/noindex-->
      

      

	
           
         
         <div style>
  <canvas id="canvas" style="width:60%;">当前浏览器不支持canvas，请更换浏览器后再试</canvas>
</div>
<script>
(function(){

   var digit=
    [
        [
            [0,0,1,1,1,0,0],
            [0,1,1,0,1,1,0],
            [1,1,0,0,0,1,1],
            [1,1,0,0,0,1,1],
            [1,1,0,0,0,1,1],
            [1,1,0,0,0,1,1],
            [1,1,0,0,0,1,1],
            [1,1,0,0,0,1,1],
            [0,1,1,0,1,1,0],
            [0,0,1,1,1,0,0]
        ],//0
        [
            [0,0,0,1,1,0,0],
            [0,1,1,1,1,0,0],
            [0,0,0,1,1,0,0],
            [0,0,0,1,1,0,0],
            [0,0,0,1,1,0,0],
            [0,0,0,1,1,0,0],
            [0,0,0,1,1,0,0],
            [0,0,0,1,1,0,0],
            [0,0,0,1,1,0,0],
            [1,1,1,1,1,1,1]
        ],//1
        [
            [0,1,1,1,1,1,0],
            [1,1,0,0,0,1,1],
            [0,0,0,0,0,1,1],
            [0,0,0,0,1,1,0],
            [0,0,0,1,1,0,0],
            [0,0,1,1,0,0,0],
            [0,1,1,0,0,0,0],
            [1,1,0,0,0,0,0],
            [1,1,0,0,0,1,1],
            [1,1,1,1,1,1,1]
        ],//2
        [
            [1,1,1,1,1,1,1],
            [0,0,0,0,0,1,1],
            [0,0,0,0,1,1,0],
            [0,0,0,1,1,0,0],
            [0,0,1,1,1,0,0],
            [0,0,0,0,1,1,0],
            [0,0,0,0,0,1,1],
            [0,0,0,0,0,1,1],
            [1,1,0,0,0,1,1],
            [0,1,1,1,1,1,0]
        ],//3
        [
            [0,0,0,0,1,1,0],
            [0,0,0,1,1,1,0],
            [0,0,1,1,1,1,0],
            [0,1,1,0,1,1,0],
            [1,1,0,0,1,1,0],
            [1,1,1,1,1,1,1],
            [0,0,0,0,1,1,0],
            [0,0,0,0,1,1,0],
            [0,0,0,0,1,1,0],
            [0,0,0,1,1,1,1]
        ],//4
        [
            [1,1,1,1,1,1,1],
            [1,1,0,0,0,0,0],
            [1,1,0,0,0,0,0],
            [1,1,1,1,1,1,0],
            [0,0,0,0,0,1,1],
            [0,0,0,0,0,1,1],
            [0,0,0,0,0,1,1],
            [0,0,0,0,0,1,1],
            [1,1,0,0,0,1,1],
            [0,1,1,1,1,1,0]
        ],//5
        [
            [0,0,0,0,1,1,0],
            [0,0,1,1,0,0,0],
            [0,1,1,0,0,0,0],
            [1,1,0,0,0,0,0],
            [1,1,0,1,1,1,0],
            [1,1,0,0,0,1,1],
            [1,1,0,0,0,1,1],
            [1,1,0,0,0,1,1],
            [1,1,0,0,0,1,1],
            [0,1,1,1,1,1,0]
        ],//6
        [
            [1,1,1,1,1,1,1],
            [1,1,0,0,0,1,1],
            [0,0,0,0,1,1,0],
            [0,0,0,0,1,1,0],
            [0,0,0,1,1,0,0],
            [0,0,0,1,1,0,0],
            [0,0,1,1,0,0,0],
            [0,0,1,1,0,0,0],
            [0,0,1,1,0,0,0],
            [0,0,1,1,0,0,0]
        ],//7
        [
            [0,1,1,1,1,1,0],
            [1,1,0,0,0,1,1],
            [1,1,0,0,0,1,1],
            [1,1,0,0,0,1,1],
            [0,1,1,1,1,1,0],
            [1,1,0,0,0,1,1],
            [1,1,0,0,0,1,1],
            [1,1,0,0,0,1,1],
            [1,1,0,0,0,1,1],
            [0,1,1,1,1,1,0]
        ],//8
        [
            [0,1,1,1,1,1,0],
            [1,1,0,0,0,1,1],
            [1,1,0,0,0,1,1],
            [1,1,0,0,0,1,1],
            [0,1,1,1,0,1,1],
            [0,0,0,0,0,1,1],
            [0,0,0,0,0,1,1],
            [0,0,0,0,1,1,0],
            [0,0,0,1,1,0,0],
            [0,1,1,0,0,0,0]
        ],//9
        [
            [0,0,0,0,0,0,0],
            [0,0,1,1,1,0,0],
            [0,0,1,1,1,0,0],
            [0,0,1,1,1,0,0],
            [0,0,0,0,0,0,0],
            [0,0,0,0,0,0,0],
            [0,0,1,1,1,0,0],
            [0,0,1,1,1,0,0],
            [0,0,1,1,1,0,0],
            [0,0,0,0,0,0,0]
        ]//:
    ];

var canvas = document.getElementById('canvas');

if(canvas.getContext){
    var cxt = canvas.getContext('2d');
    //声明canvas的宽高
    var H = 100,W = 700;
    canvas.height = H;
    canvas.width = W;
    cxt.fillStyle = '#f00';
    cxt.fillRect(10,10,50,50);

    //存储时间数据
    var data = [];
    //存储运动的小球
    var balls = [];
    //设置粒子半径
    var R = canvas.height/20-1;
    (function(){
        var temp = /(\d)(\d):(\d)(\d):(\d)(\d)/.exec(new Date());
        //存储时间数字，由十位小时、个位小时、冒号、十位分钟、个位分钟、冒号、十位秒钟、个位秒钟这7个数字组成
        data.push(temp[1],temp[2],10,temp[3],temp[4],10,temp[5],temp[6]);
    })();

    /*生成点阵数字*/
    function renderDigit(index,num){
        for(var i = 0; i < digit[num].length; i++){
            for(var j = 0; j < digit[num][i].length; j++){
                if(digit[num][i][j] == 1){
                    cxt.beginPath();
                    cxt.arc(14*(R+2)*index + j*2*(R+1)+(R+1),i*2*(R+1)+(R+1),R,0,2*Math.PI);
                    cxt.closePath();
                    cxt.fill();
                }
            }
        }
    }

    /*更新时钟*/
    function updateDigitTime(){
        var changeNumArray = [];
        var temp = /(\d)(\d):(\d)(\d):(\d)(\d)/.exec(new Date());
        var NewData = [];
        NewData.push(temp[1],temp[2],10,temp[3],temp[4],10,temp[5],temp[6]);
        for(var i = data.length-1; i >=0 ; i--){
            //时间发生变化
            if(NewData[i] !== data[i]){
                //将变化的数字值和在data数组中的索引存储在changeNumArray数组中
                changeNumArray.push(i+'_'+(Number(data[i])+1)%10);
            }
        }
        //增加小球
        for(var i = 0; i< changeNumArray.length; i++){
            addBalls.apply(this,changeNumArray[i].split('_'));
        }
        data = NewData.concat();
    }

    /*更新小球状态*/
    function updateBalls(){
        for(var i = 0; i < balls.length; i++){
            balls[i].stepY += balls[i].disY;
            balls[i].x += balls[i].stepX;
            balls[i].y += balls[i].stepY;
            if(balls[i].x > W + R || balls[i].y > H + R){
                balls.splice(i,1);
                i--;
            }
        }
    }

    /*增加要运动的小球*/
    function addBalls(index,num){
        var numArray = [1,2,3];
        var colorArray =  ["#3BE","#09C","#A6C","#93C","#9C0","#690","#FB3","#F80","#F44","#C00"];
        for(var i = 0; i < digit[num].length; i++){
            for(var j = 0; j < digit[num][i].length; j++){
                if(digit[num][i][j] == 1){
                    var ball = {
                        x:14*(R+2)*index + j*2*(R+1)+(R+1),
                        y:i*2*(R+1)+(R+1),
                        stepX:Math.floor(Math.random() * 4 -2),
                        stepY:-2*numArray[Math.floor(Math.random()*numArray.length)],
                        color:colorArray[Math.floor(Math.random()*colorArray.length)],
                        disY:1
                    };
                    balls.push(ball);
                }
            }
        }
    }

    /*渲染*/
    function render(){
        //重置画布宽度，达到清空画布的效果
        canvas.height = 100;
        //渲染时钟
        for(var i = 0; i < data.length; i++){
            renderDigit(i,data[i]);
        }
        //渲染小球
        for(var i = 0; i < balls.length; i++){
            cxt.beginPath();
            cxt.arc(balls[i].x,balls[i].y,R,0,2*Math.PI);
            cxt.fillStyle = balls[i].color;
            cxt.closePath();
            cxt.fill();
        }
    }

    clearInterval(oTimer);
    var oTimer = setInterval(function(){
        //更新时钟
        updateDigitTime();
        //更新小球状态
        updateBalls();
        //渲染
        render();
    },50);
}

})();
</script>



    </div>
  </aside>


        
      </div>
    </main>

    <footer id="footer" class="footer">
      <div class="footer-inner">
        <div class="copyright">&copy; <span itemprop="copyrightYear">2020</span>
  <span class="with-love">
    <i class="fa fa-user"></i>
  </span>
  <span class="author" itemprop="copyrightHolder">190coder</span>

  
</div>


  <div class="powered-by">Powered by <a class="theme-link" target="_blank" href="https://hexo.io">Hexo</a></div>



  <span class="post-meta-divider">|</span>



  <div class="theme-info">Theme &mdash; <a class="theme-link" target="_blank" href="https://github.com/iissnan/hexo-theme-next">NexT.Gemini</a> v5.1.4</div>





<div>
    <script async src="//busuanzi.ibruce.info/busuanzi/2.3/busuanzi.pure.mini.js"></script>
    <span id="busuanzi_container_site_pv">本站总访问量<span id="busuanzi_value_site_pv"></span>次</span>
    <span class="post-meta-divider">|</span>
    <span id="busuanzi_container_site_uv">本站访客数<span id="busuanzi_value_site_uv"></span>人</span>
</div>


        







        
      </div>
    </footer>

    
      <div class="back-to-top">
        <i class="fa fa-arrow-up"></i>
        
      </div>
    

    

  </div>

  

<script type="text/javascript">
  if (Object.prototype.toString.call(window.Promise) !== '[object Function]') {
    window.Promise = null;
  }
</script>









  


  











  
  
    <script type="text/javascript" src="/lib/jquery/index.js?v=2.1.3"></script>
  

  
  
    <script type="text/javascript" src="/lib/fastclick/lib/fastclick.min.js?v=1.0.6"></script>
  

  
  
    <script type="text/javascript" src="/lib/jquery_lazyload/jquery.lazyload.js?v=1.9.7"></script>
  

  
  
    <script type="text/javascript" src="/lib/velocity/velocity.min.js?v=1.2.1"></script>
  

  
  
    <script type="text/javascript" src="/lib/velocity/velocity.ui.min.js?v=1.2.1"></script>
  

  
  
    <script type="text/javascript" src="/lib/fancybox/source/jquery.fancybox.pack.js?v=2.1.5"></script>
  

  
  
    <script type="text/javascript" src="//cdn.jsdelivr.net/gh/theme-next/theme-next-canvas-nest@1/canvas-nest.min.js"></script>
  


  


  <script type="text/javascript" src="/js/src/utils.js?v=5.1.4"></script>

  <script type="text/javascript" src="/js/src/motion.js?v=5.1.4"></script>



  
  


  <script type="text/javascript" src="/js/src/affix.js?v=5.1.4"></script>

  <script type="text/javascript" src="/js/src/schemes/pisces.js?v=5.1.4"></script>



  
  <script type="text/javascript" src="/js/src/scrollspy.js?v=5.1.4"></script>
<script type="text/javascript" src="/js/src/post-details.js?v=5.1.4"></script>



  


  <script type="text/javascript" src="/js/src/bootstrap.js?v=5.1.4"></script>



  


  




	





  





  












  





  

  

  

  
  

  

  

  

</body>
</html>
